package snafu.framework.objects;

import java.util.UUID;

import snafu.framework.actions.AbstractAction;
import snafu.framework.actions.AbstractReaction;
import snafu.framework.states.State;
import snafu.framework.states.StateItself;
import snafu.framework.view.View;
import snafu.framework.view.ViewFactory;

public abstract class WorldObjectItself<V extends View> implements WorldObject, ViewFactory<V>{

	/** The unique id. */
	protected UUID id;
	/** The object's state. */
	protected StateItself state;
	
	/**
	 * Instantiates a new world object and assigns it a new random unique id. The state it defines
	 * through the {@link WorldObjectItself#getInitialState() initial state method}.
	 */
	public WorldObjectItself() {
		this.id = UUID.randomUUID();
		this.state = getInitialState();
	}
	
	@Override
	public UUID getId() {
		return this.id;
	}
	
	@Override
	public State getState() {
		return this.state;
	}
	
	
	/**
	 * Returns the initial state of the object as a new instance of the {@link StateItself} class.
	 * 
	 * @return the created state
	 */
	public abstract StateItself getInitialState();
	
	@Override
	public boolean equals(Object o) {
		if (!(o instanceof WorldObject))
			return false;
		
		WorldObject that = (WorldObject) o;
		return this.getId().equals(that.getId());
	}
	
	@Override
	public AbstractReaction react(AbstractAction action) {
		return null;
	}
	
	@Override
	public String toString() {
		return output();
	}
}
